package com.yuncheng.spcyApi.service.impl;

import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcySmsLog;
import com.yuncheng.spcyApi.mapper.SpcySmsLogMapper;
import com.yuncheng.spcyApi.service.ISpcySmsLogService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.GetUuIdUtils;

import com.yuncheng.vo.CurrentUserVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Description: 审评查验-短信发送记录
 * @Author: yuncheng
 * @Date: 2023-05-24
 * @Version: V1.0
 */
@Service
public class SpcySmsLogServiceImpl extends BaseServiceImpl<SpcySmsLogMapper, SpcySmsLog> implements ISpcySmsLogService {

    @Override
    public void autoAddSmsLog(String phone,String content) {
        SpcySmsLog smsLog = new SpcySmsLog();
        smsLog.setId(GetUuIdUtils.ReplaceUuId());
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser != null){
            smsLog.setFuserid(currentUser.getId());
            smsLog.setFusername(currentUser.getName());
        }
        smsLog.setFfszt(SpcyConstant.SMS_FSZT_YFS);
        smsLog.setFfssj(new Date());
        smsLog.setFzdydx(phone);
        smsLog.setFdxnr(content);
        save(smsLog);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertSmsLog(SpcySmsLog spcySmsLog) {
        if (StringUtils.isBlank(spcySmsLog.getId())){
            spcySmsLog.setId(GetUuIdUtils.ReplaceUuId());
            save(spcySmsLog);
        }else {
            updateById(spcySmsLog);
        }
    }
}
